package com.yupi.ojjudge.mq;

import com.yupi.ojjudge.judge.JudgeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @Author ortonzhu
 * @Date 2024/10/22 20:46
 */
@Component
@Slf4j
public class QuestionRunningConsumer {

    @Resource
    private JudgeService judgeService;

    @RabbitListener(bindings = @QueueBinding(value = @Queue(value = "oj-judge-queue"),
            exchange = @Exchange(value = "oj_exchange", type = ExchangeTypes.DIRECT,
                    ignoreDeclarationExceptions = "true"),
            key = {"oj_routing_key"}
    ), ackMode = "MANUAL")
    public void receiveMessage(String message) {
        log.info("receive message: {}", message);
        Long questionSubmitId = Long.parseLong(message);
        judgeService.doJudge(questionSubmitId);
    }
}
